package com.backgroundManager.biz.UserMgr;

import java.util.ArrayList;
import java.util.List;

import com.usermgr.bean.OfUser;
import com.usermgr.bean.OfUserCriteria;
import com.usermgr.dao.OfUserDAO;

/**
 *@title      	标题：
 *@description 	描述：
 *@author 	  	作者 ：wuxionghao
 *@createTime 	创建时间：2012-1-9下午03:02:49
 *@version    	版本：v1.0
 */
public class UserMgrImpl implements IUserMgr {

	private OfUserDAO userDAO;
	
	public boolean addBlacklist(Long userId) {
		return false;
	}

	//删除用户
	public boolean delUser(Long userId) {
		boolean result = false;
		if(userDAO.deleteByPrimaryKey(userId) >= 1){
			result = true;
		}
		return result;
	}
	//查找所有用户
	public List<OfUser> selectUser() {
		List<OfUser> users = new ArrayList<OfUser>();
		OfUserCriteria example = new OfUserCriteria();
		example.createCriteria().andOfIdIsNotNull();
		users = userDAO.selectByExample(example);
		return users;
	}
	//更改用户权限
	public boolean updateUserPermission(Long userId,String permession) {
		boolean result = false;
		OfUser user = new OfUser();
		user.setOfPermission(permession);
		OfUserCriteria example = new OfUserCriteria();
		example.createCriteria().andOfIdEqualTo(userId);
		int count = userDAO.updateByExampleSelective(user, example);
		if(count >= 1){
			result = true;
		}else{

		}
		return result;
	}
	//判断用户是否为管理员
	public boolean judgeUserPermission(Long userId){
		boolean result = false;
		OfUser user = userDAO.selectByPrimaryKey(userId);
		if(user.getOfPermission() != null && user.getOfPermission().equals("1")){
			result = true;
		}
		return result;
	}

	public OfUserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(OfUserDAO userDAO) {
		this.userDAO = userDAO;
	}
	
}
